package com.zhenyi.zhengfang.admin.index;

import java.util.Date;

import org.joda.time.DateTime;

import com.jfinal.aop.Before;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.StrKit;
import com.utils.DateUtils;
import com.zhenyi.core.VueUtils;
import com.zhenyi.zhengfang.core.ZFController;
import com.zhenyi.zhengfang.interceptor.AuthInterceptor;

import cn.hutool.core.date.DateUtil;
@Before( AuthInterceptor.class )
public class ZFAdminController extends ZFController {
	@Override
	public void setItems(Object items) {
		setAttr("items", JsonKit.toJson(items));
	}

	protected void setData(String name, Object info) {
		if (info == null) {
			return;
		}
		String json = VueUtils.getVueData(info);
		setAttr(name, json);
	}
	protected Date getStartTime() {
		String time = getPara("startTime");
		if (StrKit.notBlank(time)) {
			setAttr("startTime", time);
			return DateUtil.parse(time, DateUtils.YYYYMMDD_HHMMSS);
		}
		String dt = DateUtil.format(new DateTime().minusDays(7).toDate(), DateUtils.YYYYMMDD) + " 00:00:00";
		setAttr("startTime", dt);
		return DateUtil.parse(dt, DateUtils.YYYYMMDD_HHMMSS);
	}

	protected Date getEndTime() {
		String time = getPara("endTime");
		if (StrKit.notBlank(time)) {
			setAttr("endTime", time);
			return DateUtil.parse(time, DateUtils.YYYYMMDD_HHMMSS);
		}
		String dt = DateUtil.today() + " 23:59:59";
		setAttr("endTime", dt);
		return DateUtil.parse(dt, DateUtils.YYYYMMDD_HHMMSS);
	}
}
